package com.xiaoxi.open.design.structural.adapterpattern.media.adapter;

import com.xiaoxi.open.design.structural.adapterpattern.media.adaptee.AdvancedMediaPlayer;
import com.xiaoxi.open.design.structural.adapterpattern.media.player.MediaPlayer;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

/**
 * @ClassName MediaAdapter
 * @Description
 * @Author xiaoxi
 * @Date 2024/5/28 0:23
 * @Version 1.0
 */
@Service
public class MediaAdapter implements MediaPlayer {

    @Resource
    private Map<String, AdvancedMediaPlayer> advancedMediaPlayerMap;

    @Override
    public void play(String audioType, String fileName) {
        AdvancedMediaPlayer advancedMediaPlayer = advancedMediaPlayerMap.get(audioType);
        if (Objects.isNull(advancedMediaPlayer)) {
            System.out.println("当前类型暂不支持，无法播放~~~~~");
        } else {
            advancedMediaPlayer.specificPlay(fileName);
        }
    }


}
